﻿using System;
using System.Collections.Generic;
using System.Linq;
using System.Text;
using Stone.DataContracts; 

namespace Stone.Library.Common
{
    public class CommonHelper
    {
        private static string[] am_time_sec1 = { "8:00-10:00", "8:30-10:00"};
        private static string[] am_time_sec2 = { "10:00-12:00", "10:00-11:30" };
        private static string[] pm_time_sec1 = { "13:00-15:00", "13:30-15:00" };
        private static string[] pm_time_sec2 = {  "15:00-17:00", "15:00-16:30" };
        private static string[] eve_time_sec1 = { "18:00-20:00", "18:30-20:00" };
        private static string[] eve_time_sec2 = {  "20:00-22:00", "20:00-21:30" };

        private static string[] am_time_sec61 = { "6-8:00-10:00", "6-8:30-10:00" };
        private static string[] am_time_sec62 = { "6-10:00-12:00", "6-10:00-11:30" };
        private static string[] pm_time_sec61 = { "6-13:00-15:00", "6-13:30-15:00" };
        private static string[] pm_time_sec62 = { "6-15:00-17:00", "6-15:00-16:30" };
        private static string[] eve_time_sec61 = { "6-18:00-20:00", "6-18:30-20:00" };
        private static string[] eve_time_sec62 = { "6-20:00-22:00", "6-20:00-21:30" };

        private static string[] am_time_sec71 = { "7-8:00-10:00", "7-8:30-10:00" };
        private static string[] am_time_sec72 = { "7-10:00-12:00", "7-10:00-11:30" };
        private static string[] pm_time_sec71 = { "7-13:00-15:00", "7-13:30-15:00" };
        private static string[] pm_time_sec72 = { "7-15:00-17:00", "7-15:00-16:30" };
        private static string[] eve_time_sec71 = { "7-18:00-20:00", "7-18:30-20:00" };
        private static string[] eve_time_sec72 = { "7-20:00-22:00", "7-20:00-21:30" };
        
        #region string2长度系列
        // 15:30=1530
        public static int string2Int3length(string time_sec)
        {
            string[] tmpdata = time_sec.Split(':');
            int result = int.Parse(tmpdata[0]) * 100 + int.Parse(tmpdata[1]);
            return result;
        }

        // 1-15:30-17:30=1-15-30-17-30   周一第五格,下午3点半
        public static string string2string15length(string time_sec)
        {
            return time_sec.Replace(':', '-');
        }

        /// 1-15:30-17:30=>1-15-30-17-30=>11530-11730
        public static string string2string11length(string time_sec)
        {
            string[] tmp = time_sec.Replace(':','-').Split('-');
            int i = int.Parse(tmp[0])*10000 + int.Parse(tmp[1])*100 + int.Parse(tmp[2]);
            int j = int.Parse(tmp[0])*10000 + int.Parse(tmp[3])*100 + int.Parse(tmp[4]);
            string s = i.ToString() + '-' + j.ToString();
            return s;
        }

        #endregion

        #region string2DB系列
        /// <summary>
        /// 存储到数据库方法
        /// </summary>
        /// <param name="stringlist"></param>
        /// <returns></returns>
        public static string string2string2DB(List<int> stringlist)
        {
            StringBuilder sb = new StringBuilder();
            foreach (int s in stringlist)
            {
                sb.Append("[")
                    .Append(s.ToString())
                    .Append("]");
            }
            return sb.ToString(); 
        }
        public static string string2string2DB(List<string> stringlist)
        {
            StringBuilder sb = new StringBuilder();
            foreach (string s in stringlist)
            {
                sb.Append("[")
                    .Append(s)
                    .Append("]");
            }
            return sb.ToString();
        }
        public static string string2string2DB(List<DoubleInt> doubleintlist)
        {
            StringBuilder sb = new StringBuilder();
            foreach (DoubleInt di in doubleintlist)
            {
                sb.Append("[")
                    .Append(di.lowInt.ToString())
                    .Append("-")
                    .Append(di.highInt.ToString())
                    .Append("]");
            }
            return sb.ToString();
        }
        public static string string2string2DB(List<CourseEntity> celist)
        {
            StringBuilder sb = new StringBuilder();
            foreach (CourseEntity ce in celist)
            {
                sb.Append("[")
                    .Append(ce.course_name)
                    .Append("]");
            }
            return sb.ToString();
        }
        public static string string2string2DB(List<GradeEntity> gelist)
        {
            StringBuilder sb = new StringBuilder();
            foreach (GradeEntity ge in gelist)
            {
                sb.Append("[")
                    .Append(ge.grade_name)
                    .Append("]");
            }
            return sb.ToString();
        }
        #endregion

        //将时间转成节次的形式. 1-8:00-10:00=>11
        public static string course2simple(string str)
        {
            str=str.Replace("[","").Replace("]","");
            string[] tmp = str.Split(new char[] { '-' }, 2);
            
            if (am_time_sec1.Contains(tmp[1]))
                return str.Substring(0, 1) + "1";
            else if (am_time_sec2.Contains(tmp[1]))
                return str.Substring(0, 1) + "2";
            else if (pm_time_sec1.Contains(tmp[1]))
                return str.Substring(0, 1) + "3";
            else if (pm_time_sec2.Contains(tmp[1]))
                return str.Substring(0, 1) + "4";
            else if (eve_time_sec1.Contains(tmp[1]))
                return str.Substring(0, 1) + "5";
            else 
                return str.Substring(0, 1) + "6";
        }

        public static int course2multi(string str)
        {
            #region Saturday
            if (am_time_sec61[0] == str)
                return 61;
            else if (am_time_sec61[1] == str)
                return 62;
            else if (am_time_sec62[0] == str)
                return 63;
            else if (am_time_sec62[1] == str)
                return 64;
            else if (pm_time_sec61[0] == str)
                return 65;
            else if (pm_time_sec61[1] == str)
                return 66;
            else if (pm_time_sec62[0] == str)
                return 67;
            else if (pm_time_sec62[1] == str)
                return 68;
            else if (eve_time_sec61[0] == str)
                return 69;
            else if (eve_time_sec61[1] == str)
                return 610;
            else if (eve_time_sec62[0] == str)
                return 611;
            else if (eve_time_sec62[0] == str)
                return 612;
            #endregion

            #region Sunday
            else if (am_time_sec71[0] == str)
                return 71;
            else if (am_time_sec71[1] == str)
                return 72;
            else if (am_time_sec72[0] == str)
                return 73;
            else if (am_time_sec72[1] == str)
                return 74;
            else if (pm_time_sec71[0] == str)
                return 75;
            else if (pm_time_sec71[1] == str)
                return 76;
            else if (pm_time_sec72[0] == str)
                return 77;
            else if (pm_time_sec72[1] == str)
                return 78;
            else if (eve_time_sec71[0] == str)
                return 79;
            else if (eve_time_sec71[1] == str)
                return 710;
            else if (eve_time_sec72[0] == str)
                return 711;
            else if (eve_time_sec72[1] == str)
                return 712;
            else
                return 0;
            #endregion 

            #region 注释
            //string[] tmp = str.Split(new char[] { '-' }, 2);
            //if (am_time_sec1[0]==tmp[1])
            //    return 1;
            //else if (am_time_sec1[1] == tmp[1])
            //    return 2;
            //else if (am_time_sec2[0] == tmp[1])
            //    return 3;
            //else if (am_time_sec2[1] == tmp[1])
            //    return 4;
            //else if (pm_time_sec1[0] == tmp[1])
            //    return 5;
            //else if (pm_time_sec1[1] == tmp[1])
            //    return 6;
            //else if (pm_time_sec2[0] == tmp[1])
            //    return 7;
            //else if (pm_time_sec2[1] == tmp[1])
            //    return 8;
            //else if (eve_time_sec1[0] == tmp[1])
            //    return 9;
            //else if (eve_time_sec1[1] == tmp[1])
            //    return 10;
            //else if (eve_time_sec2[0] == tmp[1])
            //    return 11;
            //else 
            //    return 12;
            #endregion
        }

        #region 分解BD字段

        //分解DB中的[]
        public static string[] GetSplitString(string str)
        {
            string[] result = str.Split(new char[] { '[', ']' },StringSplitOptions.RemoveEmptyEntries);
            return result;
        }

        #endregion

        /// <summary>
        /// 判断时段
        /// </summary>
        /// <param name="timesec">输入两位字符串</param>
        /// <returns></returns>
        public static int getTimesec(string timesec)
        {
            int tmp = int.Parse(timesec);
            if (tmp < 12)
                return 0;
            else if (tmp < 18)
                return 3;
            else
                return 6;
        }

        public static List<ArrangeSecEntity> string2asEntity(List<string> time_sec)
        {
            string[] tmp;
            string tmps;
            List<ArrangeSecEntity> aseList = new List<ArrangeSecEntity>();
            foreach (string tmp_sec in time_sec)
            {
                //tmp_sec=1-15:00-17:00
                tmp = tmp_sec.Split('-');
                int tmpt =int.Parse(tmp[1].Split(':')[0]);
                if (tmpt < 12)
                    tmps = "1";
                else if (tmpt < 18)
                    tmps = "2";
                else
                    tmps = "3"; 
                aseList.Add(new ArrangeSecEntity() { 
                    tec_arrange_daysec=tmp[0],
                    tec_arrange_fixtime_start=tmp[1],
                    tec_arrange_fixtime_end=tmp[2],
                    tec_arrange_lefttime_start=tmp[3],
                    tec_arrange_lefttime_end=tmp[4]
                });
            }
            return aseList;
        }

        public static ZapEntity int2zap(List<string> course_time_int)
        {
            ZapEntity zap = new ZapEntity();
            foreach (string tmp in course_time_int)
            { 
                switch (tmp)
                {
                    #region sat
                    case "61":
                        zap.zap_sat_am1 = "√";
                        break;
                    case "62":
                        zap.zap_sat_am2 = "√";
                        break;
                    case "63":
                        zap.zap_sat_pm1 = "√";
                        break;
                    case "64":
                        zap.zap_sat_pm2 = "√";
                        break;
                    case "65":
                        zap.zap_sat_eve1 = "√";
                        break;
                    case "66":
                        zap.zap_sat_eve2 = "√";
                        break;
                    #endregion

                    #region sun
                    case "71":
                        zap.zap_sun_am1 = "√";
                        break;
                    case "72":
                        zap.zap_sun_am2 = "√";
                        break;
                    case "73":
                        zap.zap_sun_pm1 = "√";
                        break;
                    case "74":
                        zap.zap_sun_pm2 = "√";
                        break;
                    case "75":
                        zap.zap_sun_eve1 = "√";
                        break;
                    case "76":
                        zap.zap_sun_eve2 = "√";
                        break;
                    #endregion

                    #region mon
                    case "11":
                        zap.zap_mon_am1="√";
                        break;
                    case "12":
                        zap.zap_mon_am2="√";
                        break;
                    case "13":
                        zap.zap_mon_pm1 = "√";
                        break;
                    case "14":
                        zap.zap_mon_pm2 = "√";
                        break;
                    case "15":
                        zap.zap_mon_eve1 = "√";
                        break;
                    case "16":
                        zap.zap_mon_eve2 = "√";
                        break;
                    #endregion

                    #region tue
                    case "21":
                        zap.zap_tue_am1 = "√";
                        break;
                    case "22":
                        zap.zap_tue_am2 = "√";
                        break;
                    case "23":
                        zap.zap_tue_pm1 = "√";
                        break;
                    case "24":
                        zap.zap_tue_pm2 = "√";
                        break;
                    case "25":
                        zap.zap_tue_eve1 = "√";
                        break;
                    case "26":
                        zap.zap_tue_eve2 = "√";
                        break;
                    #endregion

                    #region wed
                    case "31":
                        zap.zap_wed_am1 = "√";
                        break;
                    case "32":
                        zap.zap_wed_am2 = "√";
                        break;
                    case "33":
                        zap.zap_wed_pm1 = "√";
                        break;
                    case "34":
                        zap.zap_wed_pm2 = "√";
                        break;
                    case "35":
                        zap.zap_wed_eve1 = "√";
                        break;
                    case "36":
                        zap.zap_wed_eve2 = "√";
                        break;
                    #endregion

                    #region thu
                    case "41":
                        zap.zap_thu_am1 = "√";
                        break;
                    case "42":
                        zap.zap_thu_am2 = "√";
                        break;
                    case "43":
                        zap.zap_thu_pm1 = "√";
                        break;
                    case "44":
                        zap.zap_thu_pm2 = "√";
                        break;
                    case "45":
                        zap.zap_thu_eve1 = "√";
                        break;
                    case "46":
                        zap.zap_thu_eve2 = "√";
                        break;
                    #endregion

                    #region fri
                    case "51":
                        zap.zap_fri_am1 = "√";
                        break;
                    case "52":
                        zap.zap_fri_am2 = "√";
                        break;
                    case "53":
                        zap.zap_fri_pm1 = "√";
                        break;
                    case "54":
                        zap.zap_fri_pm2 = "√";
                        break;
                    case "55":
                        zap.zap_fri_eve1 = "√";
                        break;
                    case "56":
                        zap.zap_fri_eve2 = "√";
                        break;
                    #endregion
                }
            }
            return zap;
        }

        public static ZapEntity int2zap(string course_time_int)
        {
            ZapEntity zap = new ZapEntity();
            switch (course_time_int)
            {
                #region sat
                case "61":
                    zap.zap_sat_am1 = "√";
                    break;
                case "62":
                    zap.zap_sat_am2 = "√";
                    break;
                case "63":
                    zap.zap_sat_pm1 = "√";
                    break;
                case "64":
                    zap.zap_sat_pm2 = "√";
                    break;
                case "65":
                    zap.zap_sat_eve1 = "√";
                    break;
                case "66":
                    zap.zap_sat_eve2 = "√";
                    break;
                #endregion

                #region sun
                case "71":
                    zap.zap_sun_am1 = "√";
                    break;
                case "72":
                    zap.zap_sun_am2 = "√";
                    break;
                case "73":
                    zap.zap_sun_pm1 = "√";
                    break;
                case "74":
                    zap.zap_sun_pm2 = "√";
                    break;
                case "75":
                    zap.zap_sun_eve1 = "√";
                    break;
                case "76":
                    zap.zap_sun_eve2 = "√";
                    break;
                #endregion

                #region mon
                case "11":
                    zap.zap_mon_am1 = "√";
                    break;
                case "12":
                    zap.zap_mon_am2 = "√";
                    break;
                case "13":
                    zap.zap_mon_pm1 = "√";
                    break;
                case "14":
                    zap.zap_mon_pm2 = "√";
                    break;
                case "15":
                    zap.zap_mon_eve1 = "√";
                    break;
                case "16":
                    zap.zap_mon_eve2 = "√";
                    break;
                #endregion

                #region tue
                case "21":
                    zap.zap_tue_am1 = "√";
                    break;
                case "22":
                    zap.zap_tue_am2 = "√";
                    break;
                case "23":
                    zap.zap_tue_pm1 = "√";
                    break;
                case "24":
                    zap.zap_tue_pm2 = "√";
                    break;
                case "25":
                    zap.zap_tue_eve1 = "√";
                    break;
                case "26":
                    zap.zap_tue_eve2 = "√";
                    break;
                #endregion

                #region wed
                case "31":
                    zap.zap_wed_am1 = "√";
                    break;
                case "32":
                    zap.zap_wed_am2 = "√";
                    break;
                case "33":
                    zap.zap_wed_pm1 = "√";
                    break;
                case "34":
                    zap.zap_wed_pm2 = "√";
                    break;
                case "35":
                    zap.zap_wed_eve1 = "√";
                    break;
                case "36":
                    zap.zap_wed_eve2 = "√";
                    break;
                #endregion

                #region thu
                case "41":
                    zap.zap_thu_am1 = "√";
                    break;
                case "42":
                    zap.zap_thu_am2 = "√";
                    break;
                case "43":
                    zap.zap_thu_pm1 = "√";
                    break;
                case "44":
                    zap.zap_thu_pm2 = "√";
                    break;
                case "45":
                    zap.zap_thu_eve1 = "√";
                    break;
                case "46":
                    zap.zap_thu_eve2 = "√";
                    break;
                #endregion

                #region fri
                case "51":
                    zap.zap_fri_am1 = "√";
                    break;
                case "52":
                    zap.zap_fri_am2 = "√";
                    break;
                case "53":
                    zap.zap_fri_pm1 = "√";
                    break;
                case "54":
                    zap.zap_fri_pm2 = "√";
                    break;
                case "55":
                    zap.zap_fri_eve1 = "√";
                    break;
                case "56":
                    zap.zap_fri_eve2 = "√";
                    break;
                #endregion
            }
            return zap;
        }

        public static Zap2Entity int2zap2(List<string> course_time_int)
        {
            Zap2Entity zap = new Zap2Entity();
            foreach (string tmp in course_time_int)
            {
                switch (tmp)
                {
                    #region sat
                    case "61":
                        zap.t61 = "√";
                        break;
                    case "62":
                        zap.t62 = "√";
                        break;
                    case "63":
                        zap.t63 = "√";
                        break;
                    case "64":
                        zap.t64 = "√";
                        break;
                    case "65":
                        zap.t65 = "√";
                        break;
                    case "66":
                        zap.t66 = "√";
                        break;
                    #endregion

                    #region sun
                    case "71":
                        zap.t71 = "√";
                        break;
                    case "72":
                        zap.t72 = "√";
                        break;
                    case "73":
                        zap.t73 = "√";
                        break;
                    case "74":
                        zap.t74 = "√";
                        break;
                    case "75":
                        zap.t75 = "√";
                        break;
                    case "76":
                        zap.t76 = "√";
                        break;
                    #endregion

                    #region mon
                    case "11":
                        zap.t11 = "√";
                        break;
                    case "12":
                        zap.t12 = "√";
                        break;
                    case "13":
                        zap.t13 = "√";
                        break;
                    case "14":
                        zap.t14 = "√";
                        break;
                    case "15":
                        zap.t15 = "√";
                        break;
                    case "16":
                        zap.t16 = "√";
                        break;
                    #endregion

                    #region tue
                    case "21":
                        zap.t21 = "√";
                        break;
                    case "22":
                        zap.t22 = "√";
                        break;
                    case "23":
                        zap.t23 = "√";
                        break;
                    case "24":
                        zap.t24 = "√";
                        break;
                    case "25":
                        zap.t25 = "√";
                        break;
                    case "26":
                        zap.t26 = "√";
                        break;
                    #endregion

                    #region wed
                    case "31":
                        zap.t31 = "√";
                        break;
                    case "32":
                        zap.t32 = "√";
                        break;
                    case "33":
                        zap.t33 = "√";
                        break;
                    case "34":
                        zap.t34 = "√";
                        break;
                    case "35":
                        zap.t35 = "√";
                        break;
                    case "36":
                        zap.t36 = "√";
                        break;
                    #endregion

                    #region thu
                    case "41":
                        zap.t41 = "√";
                        break;
                    case "42":
                        zap.t42 = "√";
                        break;
                    case "43":
                        zap.t43 = "√";
                        break;
                    case "44":
                        zap.t44 = "√";
                        break;
                    case "45":
                        zap.t45 = "√";
                        break;
                    case "46":
                        zap.t46 = "√";
                        break;
                    #endregion

                    #region fri
                    case "51":
                        zap.t51 = "√";
                        break;
                    case "52":
                        zap.t52 = "√";
                        break;
                    case "53":
                        zap.t53 = "√";
                        break;
                    case "54":
                        zap.t54 = "√";
                        break;
                    case "55":
                        zap.t55 = "√";
                        break;
                    case "56":
                        zap.t56 = "√";
                        break;
                    #endregion
                }
            }
            return zap;
        }

        public static Zap2Entity int2zap2(string course_time_int)
        {
            Zap2Entity zap = new Zap2Entity();
            switch (course_time_int)
            {
                #region 判断
                #region sat
                case "61":
                    zap.t61 = "√";
                    break;
                case "62":
                    zap.t62 = "√";
                    break;
                case "63":
                    zap.t63 = "√";
                    break;
                case "64":
                    zap.t64 = "√";
                    break;
                case "65":
                    zap.t65 = "√";
                    break;
                case "66":
                    zap.t66 = "√";
                    break;
                #endregion

                #region sun
                case "71":
                    zap.t71 = "√";
                    break;
                case "72":
                    zap.t72 = "√";
                    break;
                case "73":
                    zap.t73 = "√";
                    break;
                case "74":
                    zap.t74 = "√";
                    break;
                case "75":
                    zap.t75 = "√";
                    break;
                case "76":
                    zap.t76 = "√";
                    break;
                #endregion

                #region mon
                case "11":
                    zap.t11 = "√";
                    break;
                case "12":
                    zap.t12 = "√";
                    break;
                case "13":
                    zap.t13 = "√";
                    break;
                case "14":
                    zap.t14 = "√";
                    break;
                case "15":
                    zap.t15 = "√";
                    break;
                case "16":
                    zap.t16 = "√";
                    break;
                #endregion

                #region tue
                case "21":
                    zap.t21 = "√";
                    break;
                case "22":
                    zap.t22 = "√";
                    break;
                case "23":
                    zap.t23 = "√";
                    break;
                case "24":
                    zap.t24 = "√";
                    break;
                case "25":
                    zap.t25 = "√";
                    break;
                case "26":
                    zap.t26 = "√";
                    break;
                #endregion

                #region wed
                case "31":
                    zap.t31 = "√";
                    break;
                case "32":
                    zap.t32 = "√";
                    break;
                case "33":
                    zap.t33 = "√";
                    break;
                case "34":
                    zap.t34 = "√";
                    break;
                case "35":
                    zap.t35 = "√";
                    break;
                case "36":
                    zap.t36 = "√";
                    break;
                #endregion

                #region thu
                case "41":
                    zap.t41 = "√";
                    break;
                case "42":
                    zap.t42 = "√";
                    break;
                case "43":
                    zap.t43 = "√";
                    break;
                case "44":
                    zap.t44 = "√";
                    break;
                case "45":
                    zap.t45 = "√";
                    break;
                case "46":
                    zap.t46 = "√";
                    break;
                #endregion

                #region fri
                case "51":
                    zap.t51 = "√";
                    break;
                case "52":
                    zap.t52 = "√";
                    break;
                case "53":
                    zap.t53 = "√";
                    break;
                case "54":
                    zap.t54 = "√";
                    break;
                case "55":
                    zap.t55 = "√";
                    break;
                case "56":
                    zap.t56 = "√";
                    break;
                #endregion

                #endregion
            }
            return zap;
        }
    }
}
